package com.atguigu.distributed.lock.jvm;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

public class ThreadLocalTest {
    private static final ThreadLocal<String> threadLocal = new InheritableThreadLocal<>();

    //    public static void main(String[] args) {
//        threadLocal.set("main value");
//        Thread thread = new Thread(()->{
//            System.out.println("child value==>"+threadLocal.get());
//        });
//        thread.start();
//    }
    public static void main(String[] args) {
        ConcurrentHashMap<String, String> concurrentHashMap = new ConcurrentHashMap<>();
        concurrentHashMap.put("key", "value from parent thread");
        //子线程
        Thread childThread = new Thread(() -> {
            //等待父线程设置完值
            while (!concurrentHashMap.containsKey("key")) {
                //active waiting
            }
            System.out.println("child data from map==>" + concurrentHashMap.get("key"));
        });
        childThread.start();

    }

}
